# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-dns
_pkgname=dns
pkgver=6.2.2
pkgrel=3
pkgdesc="An opinionated Domain Name System (DNS) library"
url="https://github.com/mirage/ocaml-dns"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-2-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-bos-dev
	ocaml-hex-dev
	ocaml-base64-dev
	ocaml-cstruct-dev
	ocaml-domain-name-dev
	ocaml-duration-dev
	ocaml-fmt-dev
	ocaml-gmap-dev
	ocaml-happy-eyeballs-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lru-dev
	ocaml-metrics-dev
	ocaml-ptime-dev
	ocaml-ca-certs-dev
	ocaml-ca-certs-nss-dev
	ocaml-lwt-dev
	ocaml-mirage-clock-dev
	ocaml-mirage-crypto-dev
	ocaml-mirage-random-dev
	ocaml-mirage-time-dev
	ocaml-mtime-dev
	ocaml-randomconv-dev
	ocaml-tcpip-dev
	ocaml-tls-dev
	ocaml-x509-dev
	"
makedepends="$depends_dev dune ocaml ocaml-cmdliner-dev libev-dev gmp-dev"
checkdepends="ocaml-alcotest-dev"
options="!check"
subpackages="$pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/ocaml-dns/releases/download/v$pkgver/dns-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=""

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
6bb12f258114cf89b7fb0ad9bd8be80863e6e9a2d32173143fdada1534898260fddd7b5965122a67eae4cd81c3918e80b0f04a4c20f6d399e01a9a9eefbdc2b9  ocaml-dns-6.2.2.tar.bz2
"
